<?php


namespace app\common\logic;


use think\facade\Filesystem;

class File  extends LogicBase
{
    /**
     * 图片上传
     * small,medium,big
     */
    public function pictureUpload($name = 'file')
    {
        $object_info = request()->file($name);
        try{
            // fixme  这里需要完善图片上传的验证代码
            // 上传图片到本地服务器
            $result = [];
            $saveName = Filesystem::disk('public')->putFile( 'upload', $object_info, 'sha1');
            $saveName = str_replace("\\","/",$saveName);
            $result['originName'] = $object_info->getOriginalName();
            $result['path'] = "/storage/".$saveName;
            $result['url'] = "/storage/".$saveName;
            $result['uname'] = $object_info->sha1();

            return  $result;
        } catch (\Exception $e) {
            // 验证失败 输出错误信息
            exception('上传失败');
        }

    }


}
